import axios from "@/assets/request/request";
import Request from "@/assets/request";
import { Channel, LoginInfo, User, CommonInfo, SafeInfo } from "@/types/user";

export default {
  login: (data: LoginInfo) => {
    return axios({
      url: "/user/login",
      method: "post",
      data: { ...data },
    });
  },

  autoLogin: () => {
    return axios({
      url: "/user/autoLogin",
      method: "get",
    });
  },

  logout: () => {
    return axios({
      url: "/user/logout",
      method: "post",
    });
  },

  getById: (userId: string) => {
    return Request.request<User>({
      method: "GET",
      url: `/user/${userId}`,
    });
  },

  updateChannel: (data: Array<Channel>) => {
    return axios({
      url: "/user/updateChannel",
      method: "put",
      data: data,
    });
  },
  updateCommonInfo: (commonInfo: CommonInfo) => {
    return axios({
      url: "/user",
      method: "put",
      data: commonInfo,
    });
  },
  updateSensitive: (safeInfo: SafeInfo) => {
    return axios({
      url: "/user/updateSensitive",
      method: "put",
      data: safeInfo,
    });
  },
};
